<!--
 * @Description: 登录页面
 * @Author: ZY
 * @Date: 2020-12-28 16:27:50
 * @LastEditors: ZY
 * @LastEditTime: 2021-01-28 16:32:33
-->

<template>
  <div class="login-container">
    <div>
      <el-row>
        <h3 class="title_2" style="margin-top: 5%">
          蓝天信诚征信平台
        </h3>
      </el-row>
      <el-row style="
      background: -webkit-linear-gradient(bottom,#1766cb,#0649b6) no-repeat;
      height: 400px;margin-left: 20%;
      width: 60%;border-radius: 5px">
      <el-col
        :lg="12"
      >
        <img style="height: 70%;margin-left: 10%" src="../../../assets/images/login/bgpic.png">
      </el-col>
        <el-col
          :lg="3"
        ></el-col>
      <el-col
        :lg="9"
        style="margin-right: 0"
      >
        <el-card style="height: 400px;">
        <el-form
          ref="loginFormRef"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
          autocomplete="on"
          label-position="left"
        >
          <div class="title-container">
            <h3 class="title">
              欢迎登录
            </h3>
            <LangSelect
              :isWhite="true"
              class="set-language"
            />
          </div>

          <el-form-item prop="username">
        <span class="svg-container">
          <i class="el-icon-phone" />
        </span>
            <el-input
              ref="userNameRef"
              v-model="loginForm.phoneNumber"
              placeholder="请输入手机号码"
              name="username"
              type="text"
              tabindex="1"
              autocomplete="on"
            />
          </el-form-item>

          <el-tooltip
            v-model="capsTooltip"
            content="Caps lock is On"
            placement="right"
            manual
          >
            <el-form-item prop="password">
          <span class="svg-container">
            <i class="el-icon-lock" />
          </span>
              <el-input
                :key="passwordType"
                ref="passwordRef"
                v-model="loginForm.passwd"
                type="password"
                placeholder="请输入密码"
                name="password"
                tabindex="2"
                autocomplete="on"
                @blur="capsTooltip = false"
                @keyup.enter="handleLogin"
              />
              <span
                class="show-pwd"

              >
            <svg-icon
              :name="passwordType === 'password' ? 'eye-off' : 'eye-on'"
            />
          </span>
            </el-form-item>
          </el-tooltip>

          <el-button
            :loading="loading"
            type="primary"
            style="width:100%; margin-bottom:10px;background-color: #1766cb"
            @click.prevent="handleLogin"
          >
            <!--{{ t("login.logIn") }}-->
            登录
          </el-button>

          <el-link
            style="margin-left: 30%; color:#808080;"
            href="http://localhost:9999/#/signup"
          >没有账号?注册一个</el-link>
        </el-form>
        </el-card>
      </el-col>
      </el-row>
    </div>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  onMounted,
  reactive,
  watch,
  ref,
  nextTick,
  toRefs
} from 'vue'
import LangSelect from '@/components/lang_select/Index.vue'
import { isValidUsername } from '@/utils/validate'
import { useRoute, LocationQuery, useRouter } from 'vue-router'
import { useStore } from '@/store'
import { UserActionTypes } from '@/store/modules/user/action-types'
import { useI18n } from 'vue-i18n'
import Cookies from 'js-cookie'
import Keys from "@/constant/key";
export default defineComponent({
  name:'MyLogin',
  components: {
    LangSelect,
  },
  setup() {
    const userNameRef = ref(null)
    const passwordRef = ref(null)
    const loginFormRef = ref(null)
    const router = useRouter()
    const route = useRoute()
    const store = useStore()
    const { t } = useI18n()
    const state = reactive({
      loginForm: {
        phoneNumber: '',
        passwd: ''
      },
      loginRules: {
        username: [{ validator: userNameRef, trigger: 'blur' }],
        password: [{ validator: passwordRef, trigger: 'blur' }]
      },
      passwordType: 'password',
      loading: false,
      showDialog: false,
      capsTooltip: false,
      redirect: '',
      otherQuery: {}
    })




    const methods = reactive({
      handleLogin: async () => {
        console.log("jump")
        await store.dispatch(UserActionTypes.ACTION_LOGIN, state.loginForm)
        if(Cookies.get(Keys.tokenKey)) {
          router.push('/dashboard')
        }
        state.loginForm.phoneNumber = ""
        state.loginForm.passwd = ""
        setTimeout(() => {
          state.loading = false
        }, 0.5 * 1000)
      },
    })

    return {
      userNameRef,
      passwordRef,
      loginFormRef,
      ...toRefs(state),
      ...toRefs(methods),
      t,
    }
  }
})
</script>

<style lang="scss">
// References: https://www.zhangxinxu.com/wordpress/2018/01/css-caret-color-first-line/
@supports (-webkit-mask: none) and (not (cater-color: $loginCursorColor)) {
  .login-container .el-input {
    input {
      color: #808080;
    }
    input::first-line {
      color: #808080;
    }
  }
}

.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      height: 47px;
      background: transparent;
      border: 0px;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #808080;
      caret-color: #808080;
      -webkit-appearance: none;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $loginBg inset !important;
        -webkit-text-fill-color: #808080 !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style lang="scss" scoped>
.login-container {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-image: url("../../../assets/images/login/bg.png");
  background-size: cover;
  // background-color: $loginBg;
  video {
    position: absolute;
    /* Vertical and Horizontal center*/
    top: 0; left: 0; right: 0; bottom: 0;
    width:100%;
    height:100%;
    object-fit: cover;
    z-index: -1;
  }
  .login-form {
    position: relative;
    width: 300px;
    max-width: 100%;
    //padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $darkGray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: #1766cb;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }

    .title {
      font-size: 26px;
      color: #1766cb;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }

    .set-language {
      color: #fff;
      position: absolute;
      top: 3px;
      font-size: 18px;
      right: 0px;
      cursor: pointer;
    }
  }

  .title_2 {
    font-size: 45px;
    //color: #EFF5FC ;
    color: #fff;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $darkGray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
</style>
